package com.example.informationEntry.service.impl;

import com.example.informationEntry.dao.NaEmergencyContactRelationshipDao;
import com.example.informationEntry.entity.NaEmergencyContactRelationship;
import com.example.informationEntry.service.NaEmergencyContactRelationshipService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 紧急联系人关系(NaEmergencyContactRelationship)表服务实现类
 *
 * @author makejava
 * @since 2019-04-08 11:20:34
 */
@Service("naEmergencyContactRelationshipService")
public class NaEmergencyContactRelationshipServiceImpl implements NaEmergencyContactRelationshipService {
    @Resource
    private NaEmergencyContactRelationshipDao naEmergencyContactRelationshipDao;

    /**
     * 通过ID查询单条数据
     *
     * @param emergencyContactRelationshipId 主键
     * @return 实例对象
     */
    @Override
    public NaEmergencyContactRelationship queryById(String emergencyContactRelationshipId) {
        return this.naEmergencyContactRelationshipDao.queryById(emergencyContactRelationshipId);
    }

    /**
     * 查询多条数据
     *
     * @param emergencyContactRelationship 联系人关系
     * @return 对象列表
     */
    @Override
    public List<NaEmergencyContactRelationship> queryAllByName(String emergencyContactRelationship) {
        return this.naEmergencyContactRelationshipDao.queryAllByName(emergencyContactRelationship);
    }

    /**
     * 查询多条数据
     *
     * @param naEmergencyContactRelationship 实例对象
     * @return list集合
     */
    @Override
    public List<NaEmergencyContactRelationship> queryAll(NaEmergencyContactRelationship naEmergencyContactRelationship){
        return this.naEmergencyContactRelationshipDao.queryAll(naEmergencyContactRelationship);
    }

    /**
     * 新增数据
     *
     * @param naEmergencyContactRelationship 实例对象
     * @return 实例对象
     */
    @Override
    public NaEmergencyContactRelationship insert(NaEmergencyContactRelationship naEmergencyContactRelationship) {
        this.naEmergencyContactRelationshipDao.insert(naEmergencyContactRelationship);
        return naEmergencyContactRelationship;
    }

    /**
     * 修改数据
     *
     * @param naEmergencyContactRelationship 实例对象
     * @return 实例对象
     */
    @Override
    public NaEmergencyContactRelationship update(NaEmergencyContactRelationship naEmergencyContactRelationship) {
        this.naEmergencyContactRelationshipDao.update(naEmergencyContactRelationship);
        return this.queryById(naEmergencyContactRelationship.getEmergencyContactRelationshipNumber());
    }

    /**
     * 通过主键删除数据
     *
     * @param emergencyContactRelationshipId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String emergencyContactRelationshipId) {
        return this.naEmergencyContactRelationshipDao.deleteById(emergencyContactRelationshipId) > 0;
    }

    /**
     * k ID  V值
     *
     * @return 规整后的数据
     */
    @Override
    public Map<String,String> queryNumberToName(){
        Map<String,String> resultMap = new HashMap<>();
        List<NaEmergencyContactRelationship> resultList = this.queryAll(new NaEmergencyContactRelationship());
        for (NaEmergencyContactRelationship relationship : resultList) {
            resultMap.put(relationship.getEmergencyContactRelationshipNumber(),relationship.getEmergencyContactRelationship());
        }
        return resultMap;
    }
}